<?php
declare(strict_types=1);
/**
 * Created by project.
 * User: huanzipap
 * Date: 2023/5/11
 * Time: 15:01
 */

namespace App\Model;

use Hyperf\Database\Model\Model;
use Hyperf\Database\Model\SoftDeletes;

class Task extends Model
{
    use SoftDeletes;

    protected ?string $table='task';
    public bool $timestamps = true;

    protected array $fillable = ['party_id','type','title','photo','content','media_list','status','party_list','admin_id'];


    public function party(): \Hyperf\Database\Model\Relations\belongsTo
    {
        return $this->belongsTo(Party::class, 'party_id', 'id');
    }

    public function joinStatus(): \Hyperf\Database\Model\Relations\hasOne
    {
        return $this->hasOne(Notify::class, 'relation_id', 'id');
    }


    public function setMediaListAttribute($value)
    {
        $this->attributes['media_list'] = implode(',', $value);
    }

    public function getMediaListAttribute($value): array
    {
        return $value != null ? explode(',', $value) : [];
    }



    public function setPartyListAttribute($value)
    {
        $this->attributes['party_list'] = implode(',', $value);
    }

    public function getPartyListAttribute($value): array
    {
        return $value != null ? explode(',', $value) : [];
    }




    public function getContentAttribute($value): string
    {
        return $value != null ? htmlspecialchars_decode($value) : '';
    }

    public function setContentAttribute($value): void
    {
        if($value!='') htmlspecialchars($value);
        $this->attributes['content'] = $value;
    }


}